package android.medicalcloud.com.yiapp.yilian.im.model;

import android.content.Context;
import android.content.Intent;
import android.medicalcloud.com.yiapp.R;
import android.medicalcloud.com.yiapp.yilian.application.YilianAppcation;

import com.tencent.TIMUserProfile;

import java.net.URLDecoder;

/**
 * 好友资料
 */
public class FriendProfile implements ProfileSummary {


    private TIMUserProfile profile;
    private boolean isSelected;

    public FriendProfile() {
    }


    public String getHospital(){
        try {
            return new String(profile.getCustomInfo().get("Tag_Profile_Custom_h"));
        }catch (Exception e){
            return "";
        }

    }

    public String getTel() {
        try {
            return new String(profile.getCustomInfo().get("Tag_Profile_Custom_tel"));
        } catch (Exception e) {
            return "";
        }

    }

    public String getDepartment(){
        try {
            return new String(profile.getCustomInfo().get("Tag_Profile_Custom_hd"));
        }catch (Exception e){
            return "";
        }

    }

    public String getHospitalTitle(){
        try {
            return new String(profile.getCustomInfo().get("Tag_Profile_Custom_ht"));
        }catch (Exception e){
            return "";
        }

    }
    public FriendProfile(TIMUserProfile profile){
        this.profile = profile;
    }

    public TIMUserProfile getProfile() {
        return profile;
    }

    /**
     * 获取头像资源
     */
    @Override
    public int getAvatarRes() {
        return R.drawable.head_other;
    }

    /**
     * 获取头像地址
     */
    @Override
    public String getAvatarUrl() {
        try {
            return URLDecoder.decode(profile.getFaceUrl(),"UTF-8");
        }catch (Exception e){
            return profile.getFaceUrl();
        }

    }

    /**
     * 获取名字
     */
    @Override
    public String getName() {
        try {
            if (!profile.getRemark().equals("")){
                return URLDecoder.decode( profile.getRemark(),"UTF-8");
            }else if (!profile.getNickName().equals("")){
                return URLDecoder.decode( profile.getNickName(),"UTF-8");
            }
            return profile.getIdentifier();
        }catch (Exception e){}
        return "";

    }

    /**
     * 获取描述信息
     */
    @Override
    public String getDescription() {
        return null;
    }

    /**
     * 显示详情
     *
     * @param context 上下文
     */
    @Override
    public void onClick(Context context) {
//        if (FriendshipInfo.getInstance().isFriend(profile.getIdentifier())){
//            ProfileActivity.navToProfile(context, profile.getIdentifier());
//        }else{
//            Intent person = new Intent(context,AddFriendActivity.class);
//            person.putExtra("id",profile.getIdentifier());
//            person.putExtra("name",getName());
//            context.startActivity(person);
//        }
    }

    public boolean isSelected() {
        return isSelected;
    }

    public void setIsSelected(boolean isSelected) {
        this.isSelected = isSelected;
    }
    /**
     * 获取用户ID
     */
    @Override
    public String getIdentify(){
        return profile.getIdentifier();
    }


    /**
     * 获取用户备注名
     */
    public String getRemark(){
        return profile.getRemark();
    }


    /**
     * 获取好友分组
     */
    public String getGroupName(){
        if (profile.getFriendGroups().size() == 0){
            return YilianAppcation.getInstance().getContext().getString(R.string.default_group_name);
        }else{
            return profile.getFriendGroups().get(0);
        }
    }

}
